﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Steamrunner
{
    class PlayScreen : Screen
    {
        IniFile config = null;
        Viewport fullwindow;

        string nextScreen;

        public Rectangle screenBoundaries;

        LevelManager levelManager = null;
        PlayerManager playerManager = null;
        SpriteSheetManager spritesheetManager = null;
        CameraManager cameraManager = null;

        Texture2D guiInterface = null;
        Texture2D skyTexture = null;
        Texture2D cityTexture = null;

        Texture2D ci = null;
        Texture2D ty = null;

        Texture2D finish = null;

        SpriteFont placeFont = null;
        SpriteFont timeFont = null;
        SpriteFont savingFont = null;

        Texture2D blueSquare = null;
        Texture2D greenSquare = null;
        Texture2D yellowSquare = null;
        Texture2D redSquare = null;
        Texture2D saveBG = null;

        Texture2D line = null;
        Texture2D blueHead = null;
        Texture2D greenHead = null;
        Texture2D yellowHead = null;
        Texture2D redHead = null;

        Score score = null;
        Highscore highscoreList = null;
        List<float> extraX = null;
        int playerAmount;
        float levelEnd = 28500f;
        bool[] savingHighscore;
        bool[] noHighscore;
        string[] highscoreNames;

        string[] yesNo = new string[2] { "NO", "YES" };
        int[] yesNoIndex = new int[4] { 0, 0, 0, 0 };

        string[] alpabet = new string[26] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
        int[] firstName = new int[4] { 0, 0, 0, 0 };
        int[] secondName = new int[4] { 0, 0, 0, 0 };
        int[] thirdName = new int[4] { 0, 0, 0, 0 };
        int[] fourthName = new int[4] { 0, 0, 0, 0 };

        int firstFocus = 0;
        int secondFocus = 0;
        int thirdFocus = 0;
        int fourthFocus = 0;

        public PlayScreen(ScreenManager screenManager, Game game)
            : base(screenManager, game)
        {
        }

        public override void Initialize()
        {
            yesNoIndex = new int[4] { 0, 0, 0, 0 };

            firstName = new int[4] { 0, 0, 0, 0 };
            secondName = new int[4] { 0, 0, 0, 0 };
            thirdName = new int[4] { 0, 0, 0, 0 };
            fourthName = new int[4] { 0, 0, 0, 0 };

            firstFocus = 0;
            secondFocus = 0;
            thirdFocus = 0;
            fourthFocus = 0;

            config = new IniFile("config.ini");
            config.Parse();

            extraX = new List<float>();
            extraX.Add(300f);
            extraX.Add(200f);
            extraX.Add(100f);

            levelManager = new LevelManager(Game, Spritebatch);
            levelManager.Initialize();

            playerManager = new PlayerManager(Game);
            playerManager.Initialize();

            spritesheetManager = new SpriteSheetManager(Game);
            spritesheetManager.Initialize();
            
            playerAmount = (int)config.GetValue("Players", "Amount");
            savingHighscore = new bool[playerAmount];
            noHighscore = new bool[playerAmount];
            highscoreNames = new string[playerAmount];
            for (int i = 0; i < playerAmount; i++)
            {
                Player player = new Player(Game, Spritebatch, inputManager, i, spritesheetManager, levelManager, musicManager);
                player.Initialize();

                playerManager.AddPlayer(player.PlayerId, player);
                savingHighscore[i] = false;
                noHighscore[i] = false;
            }

            cameraManager = new CameraManager(Game.Window.ClientBounds.Width, Game.Window.ClientBounds.Height);
            cameraManager.Initialize();

            if (score == null)
            {
                score = new Score();
            }
            score.Flush((short)playerAmount);

            highscoreList = new Highscore("highscore.ini");
            highscoreList.Initialize();

            musicManager.PlayMusic("SteamrunnerTheme");

            base.Initialize();
        }

        protected override void LoadContent()
        {
            screenBoundaries = Game.Window.ClientBounds;
            fullwindow = new Viewport();
            fullwindow.X = 0;
            fullwindow.Y = 0;
            fullwindow.Width = Game.Window.ClientBounds.Width;
            fullwindow.Height = Game.Window.ClientBounds.Height;

            guiInterface = Game.Content.Load<Texture2D>(@"Images\Ingame\gui");
            skyTexture = Game.Content.Load<Texture2D>(@"Images\ingame\sunset");
            cityTexture = Game.Content.Load <Texture2D>(@"Images\ingame\city");

            ci = Game.Content.Load<Texture2D>(@"Images\ingame\ci");
            ty = Game.Content.Load<Texture2D>(@"Images\ingame\ty");

            placeFont = Game.Content.Load<SpriteFont>(@"Fonts\placeFont");
            timeFont = Game.Content.Load<SpriteFont>(@"Fonts\timeFont");
            savingFont = Game.Content.Load<SpriteFont>(@"Fonts\saveHighscore");

            finish = Game.Content.Load<Texture2D>(@"Images\Ingame\finish");

            blueSquare = Game.Content.Load<Texture2D>(@"Images\Ingame\square_blue");
            greenSquare = Game.Content.Load<Texture2D>(@"Images\Ingame\square_green");
            yellowSquare = Game.Content.Load<Texture2D>(@"Images\Ingame\square_yellow");
            redSquare = Game.Content.Load<Texture2D>(@"Images\Ingame\square_red");
            saveBG = Game.Content.Load<Texture2D>(@"Images\Ingame\save_bg");

            blueHead = Game.Content.Load<Texture2D>(@"Images\Ingame\blue_head");
            greenHead = Game.Content.Load<Texture2D>(@"Images\Ingame\green_head");
            yellowHead = Game.Content.Load<Texture2D>(@"Images\Ingame\yellow_head");
            redHead = Game.Content.Load<Texture2D>(@"Images\Ingame\red_head");

            line = Game.Content.Load<Texture2D>(@"Images\Ingame\Map");
        }

        public override void Update(GameTime gameTime)
        {
            musicManager.Update(gameTime);

            inputManager.Update(gameTime);

            playerManager.Update(gameTime);

            if (inputManager.JustReleased(Keys.Escape) || inputManager.JustReleased(Keys.Enter))
            {
                nextScreen = "MenuScreen";
                musicManager.StopMusic();
                screenManager.CurrentScreen = nextScreen;
            }

            for (int i = 0; i < playerAmount; i++)
            {
                // 1 = WASD
                // 2 = UHJK
                // 3 = 5123
                // 4 = UpLeftDownRight
                if (savingHighscore[i])
                {
                    switch (i)
                    {
                        case 0 :
                            if (inputManager.JustPressed(Keys.D))
                            {
                                firstFocus++;
                                if (firstFocus > 4)
                                {
                                    firstFocus = 4;
                                }
                            }
                            else if (inputManager.JustPressed(Keys.A))
                            {
                                firstFocus--;
                                if (firstFocus < 0)
                                {
                                    firstFocus = 0;
                                }
                            }

                            if (firstFocus == 4)
                            {
                                if (inputManager.JustPressed(Keys.S) || inputManager.JustPressed(Keys.W))
                                {
                                    yesNoIndex[i] = 1;
                                }
                            }
                            else
                            {
                                if (inputManager.JustPressed(Keys.W))
                                {
                                    firstName[firstFocus]--;
                                    if (firstName[firstFocus] < 0)
                                    {
                                        firstName[firstFocus] = 25;
                                    }
                                }
                                else if (inputManager.JustPressed(Keys.S))
                                {
                                    firstName[firstFocus]++;
                                    if (firstName[firstFocus] > 25)
                                    {
                                        firstName[firstFocus] = 0;
                                    }
                                }
                            }

                            if (yesNoIndex[i] == 1)
                            {
                                savingHighscore[i] = false;
                                int[] tempTime = score.PlayerTimes[i];
                                int firstTime = tempTime[0] * 100000 + tempTime[1] * 1000 + tempTime[2];
                                string tempName = alpabet[firstName[0]] + alpabet[firstName[1]] + alpabet[firstName[2]] + alpabet[firstName[3]];
                                highscoreList.AddScore(tempName, firstTime);
                            }
                            break;
                        case 1 :
                            if (inputManager.JustPressed(Keys.K))
                            {
                                secondFocus++;
                                if (secondFocus > 4)
                                {
                                    secondFocus = 4;
                                }
                            }
                            else if (inputManager.JustPressed(Keys.H))
                            {
                                secondFocus--;
                                if (secondFocus < 0)
                                {
                                    secondFocus = 0;
                                }
                            }

                            if (secondFocus == 4)
                            {
                                if (inputManager.JustPressed(Keys.J) || inputManager.JustPressed(Keys.U))
                                {
                                    yesNoIndex[i] = 1;
                                }
                            }
                            else
                            {
                                if (inputManager.JustPressed(Keys.U))
                                {
                                    secondName[secondFocus]--;
                                    if (secondName[secondFocus] < 0)
                                    {
                                        secondName[secondFocus] = 25;
                                    }
                                }
                                else if (inputManager.JustPressed(Keys.J))
                                {
                                    secondName[secondFocus]++;
                                    if (secondName[secondFocus] > 25)
                                    {
                                        secondName[secondFocus] = 0;
                                    }
                                }
                            }

                            if (yesNoIndex[i] == 1)
                            {
                                savingHighscore[i] = false;
                                int[] tempTime = score.PlayerTimes[i];
                                int secondTime = tempTime[0] * 100000 + tempTime[1] * 1000 + tempTime[2];
                                string tempName = alpabet[secondName[0]] + alpabet[secondName[1]] + alpabet[secondName[2]] + alpabet[secondName[3]];
                                highscoreList.AddScore(tempName, secondTime);
                            }
                            break;
                        case 2 :
                            if (inputManager.JustPressed(Keys.NumPad3))
                            {
                                thirdFocus++;
                                if (thirdFocus > 4)
                                {
                                    thirdFocus = 4;
                                }
                            }
                            else if (inputManager.JustPressed(Keys.NumPad1))
                            {
                                thirdFocus--;
                                if (thirdFocus < 0)
                                {
                                    thirdFocus = 0;
                                }
                            }

                            if (thirdFocus == 4)
                            {
                                if (inputManager.JustPressed(Keys.NumPad2) || inputManager.JustPressed(Keys.NumPad5))
                                {
                                    yesNoIndex[i] = 1;
                                }
                            }
                            else
                            {
                                if (inputManager.JustPressed(Keys.NumPad5))
                                {
                                    thirdName[thirdFocus]--;
                                    if (thirdName[thirdFocus] < 0)
                                    {
                                        thirdName[thirdFocus] = 25;
                                    }
                                }
                                else if (inputManager.JustPressed(Keys.NumPad2))
                                {
                                    thirdName[thirdFocus]++;
                                    if (thirdName[thirdFocus] > 25)
                                    {
                                        thirdName[thirdFocus] = 0;
                                    }
                                }
                            }

                            if (yesNoIndex[i] == 1)
                            {
                                savingHighscore[i] = false;
                                int[] tempTime = score.PlayerTimes[i];
                                int thirdTime = tempTime[0] * 100000 + tempTime[1] * 1000 + tempTime[2];
                                string tempName = alpabet[thirdName[0]] + alpabet[thirdName[1]] + alpabet[thirdName[2]] + alpabet[thirdName[3]];
                                highscoreList.AddScore(tempName, thirdTime);
                            }
                            break;
                        case 3 :
                            if (inputManager.JustPressed(Keys.Right))
                            {
                                fourthFocus++;
                                if (fourthFocus > 4)
                                {
                                    fourthFocus = 4;
                                }
                            }
                            else if (inputManager.JustPressed(Keys.Left))
                            {
                                fourthFocus--;
                                if (fourthFocus < 0)
                                {
                                    fourthFocus = 0;
                                }
                            }

                            if (fourthFocus == 4)
                            {
                                if (inputManager.JustPressed(Keys.Down) || inputManager.JustPressed(Keys.Up))
                                {
                                    yesNoIndex[i] = 1;
                                }
                            }
                            else
                            {
                                if (inputManager.JustPressed(Keys.Up))
                                {
                                    fourthName[fourthFocus]--;
                                    if (fourthName[fourthFocus] < 0)
                                    {
                                        fourthName[fourthFocus] = 25;
                                    }
                                }
                                else if (inputManager.JustPressed(Keys.Down))
                                {
                                    fourthName[fourthFocus]++;
                                    if (fourthName[fourthFocus] > 25)
                                    {
                                        fourthName[fourthFocus] = 0;
                                    }
                                }
                            }

                            if (yesNoIndex[i] == 1)
                            {
                                savingHighscore[i] = false;
                                int[] tempTime = score.PlayerTimes[i];
                                int fourthTime = tempTime[0] * 100000 + tempTime[1] * 1000 + tempTime[2];
                                string tempName = alpabet[fourthName[0]] + alpabet[fourthName[1]] + alpabet[fourthName[2]] + alpabet[fourthName[3]];
                                highscoreList.AddScore(tempName, fourthTime);
                            }
                            break;
                    }
                }
            }
            
            List<Vector2> cameraPositions = playerManager.GetPlayerPositions();

            int j = 0;
            foreach (Vector2 position in cameraPositions)
            {
                if (position.X > levelEnd && j < playerAmount && playerManager.GetPlayer(j).CurrentState != (int)Enums.State.FINISHED)
                {
                    playerManager.GetPlayer(j).CurrentState = (int)Enums.State.FINISHED;
                    score.DeactivatePlayer(j);

                    int[] playerTime = score.PlayerTimes[j];
                    int highscore = playerTime[0] * 100000 + playerTime[1] * 1000 + playerTime[2];
                    if (highscoreList.IsScoreGoodEnough(highscore))
                    {
                        savingHighscore[j] = true;
                    }
                    else
                    {
                        noHighscore[j] = true;
                    }

                    if (extraX.Count != 0)
                    {
                        Vector2 temp = playerManager.GetPlayerPosition(j);
                        temp.X += extraX[0];
                        playerManager.GetPlayer(j).Position = temp;
                        extraX.RemoveAt(0);
                    }
                }
                j++;
            }

            for (int i = 0; i < playerAmount; i++)
            {
                if (savingHighscore[i])
                {
                    break;
                }
                if (playerManager.GetPlayer(i).CurrentState != (int)Enums.State.FINISHED)
                {
                    break;
                }
                if (i == playerAmount - 1)
                {
                    nextScreen = "GameOverScreen";
                    musicManager.StopMusic();
                    screenManager.CurrentScreen = nextScreen;
                }
            }

            for (int i = 0; i < cameraPositions.Count; i++)
            {
                cameraPositions[i] = new Vector2(cameraPositions[i].X + 300f, cameraPositions[i].Y - 30f);
                if (cameraPositions[i].X > levelEnd + 100f)
                {
                    cameraPositions[i] = new Vector2(levelEnd + 100f, cameraPositions[i].Y);
                }
            }

            cameraManager.Update(cameraPositions);

            if (playerManager.GetPlayer(0).CurrentState != (int)Enums.State.NOTSTARTED)
            {
                score.Update(gameTime);
            }

            score.PlayerPlaces = CalculatePlayerPlaces();

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            Spritebatch.Begin();

            GraphicsDevice.Viewport = fullwindow;

            Spritebatch.Draw(skyTexture, Vector2.Zero, Color.White);

            Spritebatch.End();

            //////
            Spritebatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, cameraManager.GetCamera(0).Transform);
            GraphicsDevice.Viewport = cameraManager.GetViewport(0);
            Spritebatch.End();
            /////////

            for (int i = 0; i < 4; i++)
            {
                if (cameraManager.GetCameraInUse(i))
                {
                    Spritebatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, cameraManager.GetCamera(i).Transform);
                    GraphicsDevice.Viewport = cameraManager.GetViewport(i);

                    Rectangle cameraView = new Rectangle((int)cameraManager.GetCamera(i).Position.X - screenBoundaries.Width / 4 - 50, (int)cameraManager.GetCamera(i).Position.Y - screenBoundaries.Height / 4 - 50, screenBoundaries.Width / 2 + 100, screenBoundaries.Height / 2 + 100);

                    DrawCity(cameraView.X, cameraView.X + cameraView.Width);

                    DrawFinish(cameraView.X, cameraView.X + cameraView.Width);

                    levelManager.Draw(gameTime, cameraView);

                    playerManager.DrawPlayers(gameTime);

                    if (i == (int)Enums.PlayerColor.BLUE)
                    {
                        playerManager.DrawPlayer(gameTime, "blue");
                    }
                    else if (i == (int)Enums.PlayerColor.GREEN)
                    {
                        playerManager.DrawPlayer(gameTime, "green");
                    }
                    else if (i == (int)Enums.PlayerColor.RED)
                    {
                        playerManager.DrawPlayer(gameTime, "red");
                    }
                    else if (i == (int)Enums.PlayerColor.YELLOW)
                    {
                        playerManager.DrawPlayer(gameTime, "yellow");
                    }

                    Spritebatch.End();
                }
            }

            Spritebatch.Begin();

            GraphicsDevice.Viewport = fullwindow;

            Spritebatch.Draw(guiInterface, Vector2.Zero, Color.White);

            // Draw Score
            Vector2 tempPos = new Vector2(49f, 345f);
            String tempText = "";
            List<short> places = score.PlayerPlaces;

            for (int i = 0; i < playerAmount; i++)
            {
                switch (i)
                {
                    case 0 :
                        tempText = places[i].ToString();
                        Spritebatch.DrawString(placeFont, tempText, tempPos, Color.Black);
                        break;
                    case 1 :
                        tempText = places[i].ToString();
                        tempPos.X += 800;
                        Spritebatch.DrawString(placeFont, tempText, tempPos, Color.Black);
                        break;
                    case 2 :
                        tempText = places[i].ToString();
                        tempPos.X -= 800;
                        tempPos.Y += 450;
                        Spritebatch.DrawString(placeFont, tempText, tempPos, Color.Black);
                        break;
                    case 3 :
                        tempText = places[i].ToString();
                        tempPos.X += 800;
                        Spritebatch.DrawString(placeFont, tempText, tempPos, Color.Black);
                        break;
                }
            }

            tempPos = new Vector2(30f, 20f);
            List<int[]> times = score.PlayerTimes;
            

            for (int i = 0; i < playerAmount; i++)
            {
                switch (i)
                {
                    case 0:
                        tempText = times[i].GetValue(0).ToString() + ":";
                        if ((int)times[i].GetValue(1) < 10)
                        {
                            tempText += "0";
                        }
                        tempText += times[i].GetValue(1).ToString() + ":";
                        if ((int)times[i].GetValue(2) < 10)
                        {
                            tempText += "00";
                        }
                        else if ((int)times[i].GetValue(2) < 100)
                        {
                            tempText += "0";
                        }
                        tempText += times[i].GetValue(2).ToString();

                        Spritebatch.DrawString(timeFont, tempText, tempPos, Color.Black);
                        break;
                    case 1:
                        tempText = times[i].GetValue(0).ToString() + ":";
                        if ((int)times[i].GetValue(1) < 10)
                        {
                            tempText += "0";
                        }
                        tempText += times[i].GetValue(1).ToString() + ":";
                        if ((int)times[i].GetValue(2) < 10)
                        {
                            tempText += "00";
                        }
                        else if ((int)times[i].GetValue(2) < 100)
                        {
                            tempText += "0";
                        }
                        tempText += times[i].GetValue(2).ToString();

                        tempPos.X += 800;

                        Spritebatch.DrawString(timeFont, tempText, tempPos, Color.Black);
                        break;
                    case 2:
                        tempText = times[i].GetValue(0).ToString() + ":";
                        if ((int)times[i].GetValue(1) < 10)
                        {
                            tempText += "0";
                        }
                        tempText += times[i].GetValue(1).ToString() + ":";
                        if ((int)times[i].GetValue(2) < 10)
                        {
                            tempText += "00";
                        }
                        else if ((int)times[i].GetValue(2) < 100)
                        {
                            tempText += "0";
                        }
                        tempText += times[i].GetValue(2).ToString();

                        tempPos.X -= 800;
                        tempPos.Y += 450;

                        Spritebatch.DrawString(timeFont, tempText, tempPos, Color.Black);
                        break;
                    case 3:
                        tempText = times[i].GetValue(0).ToString() + ":";
                        if ((int)times[i].GetValue(1) < 10)
                        {
                            tempText += "0";
                        }
                        tempText += times[i].GetValue(1).ToString() + ":";
                        if ((int)times[i].GetValue(2) < 10)
                        {
                            tempText += "00";
                        }
                        else if ((int)times[i].GetValue(2) < 100)
                        {
                            tempText += "0";
                        }
                        tempText += times[i].GetValue(2).ToString();

                        tempPos.X += 800;

                        Spritebatch.DrawString(timeFont, tempText, tempPos, Color.Black);
                        break;
                }
            }

            // LinjeKarta
            tempPos = new Vector2(screenBoundaries.Width * 0.13f, screenBoundaries.Height * 0.415f);
            Spritebatch.Draw(line, tempPos, Color.White);
            if (playerAmount > 1)
            {
                Spritebatch.Draw(line, new Vector2(tempPos.X + (screenBoundaries.Width * 0.5f), tempPos.Y), Color.White);
            }
            if (playerAmount > 2)
            {
                Spritebatch.Draw(line, new Vector2(tempPos.X, tempPos.Y + (screenBoundaries.Height * 0.5f)), Color.White);
            }
            if (playerAmount > 3)
            {
                Spritebatch.Draw(line, new Vector2(tempPos.X + (screenBoundaries.Width * 0.5f), tempPos.Y + (screenBoundaries.Height * 0.5f)), Color.White);
            }
            List<float> headPositions = MapHeadPositions();
            tempPos = new Vector2(screenBoundaries.Width * 0.118f, screenBoundaries.Height * 0.415f);
            for (int i = 0; i < headPositions.Count; i++)
            {
                if (i == 0)
                {
                    if (headPositions.Count == 4)
                    {
                        Spritebatch.Draw(greenHead, new Vector2(tempPos.X + headPositions[3], tempPos.Y), Color.White);
                        Spritebatch.Draw(yellowHead, new Vector2(tempPos.X + headPositions[2], tempPos.Y), Color.White);
                        Spritebatch.Draw(redHead, new Vector2(tempPos.X + headPositions[1], tempPos.Y), Color.White);
                        Spritebatch.Draw(blueHead, new Vector2(tempPos.X + headPositions[0], tempPos.Y), Color.White);
                    }
                    else if (headPositions.Count == 3)
                    {
                        Spritebatch.Draw(yellowHead, new Vector2(tempPos.X + headPositions[2], tempPos.Y), Color.White);
                        Spritebatch.Draw(redHead, new Vector2(tempPos.X + headPositions[1], tempPos.Y), Color.White);
                        Spritebatch.Draw(blueHead, new Vector2(tempPos.X + headPositions[0], tempPos.Y), Color.White);
                    }
                    else if (headPositions.Count == 2)
                    {
                        Spritebatch.Draw(redHead, new Vector2(tempPos.X + headPositions[1], tempPos.Y), Color.White);
                        Spritebatch.Draw(blueHead, new Vector2(tempPos.X + headPositions[0], tempPos.Y), Color.White);
                    }
                    else
                    {
                        Spritebatch.Draw(blueHead, new Vector2(tempPos.X + headPositions[0], tempPos.Y), Color.White);
                    }
                    tempPos = new Vector2(tempPos.X + (screenBoundaries.Width * 0.5f), tempPos.Y);
                }
                else if (i == 1)
                {
                    if (headPositions.Count == 4)
                    {
                        Spritebatch.Draw(greenHead, new Vector2(tempPos.X + headPositions[3], tempPos.Y), Color.White);
                        Spritebatch.Draw(yellowHead, new Vector2(tempPos.X + headPositions[2], tempPos.Y), Color.White);
                        Spritebatch.Draw(blueHead, new Vector2(tempPos.X + headPositions[0], tempPos.Y), Color.White);
                        Spritebatch.Draw(redHead, new Vector2(tempPos.X + headPositions[1], tempPos.Y), Color.White);
                    }
                    else if (headPositions.Count == 3)
                    {
                        Spritebatch.Draw(yellowHead, new Vector2(tempPos.X + headPositions[2], tempPos.Y), Color.White);
                        Spritebatch.Draw(blueHead, new Vector2(tempPos.X + headPositions[0], tempPos.Y), Color.White);
                        Spritebatch.Draw(redHead, new Vector2(tempPos.X + headPositions[1], tempPos.Y), Color.White);
                    }
                    else if (headPositions.Count == 2)
                    {
                        Spritebatch.Draw(blueHead, new Vector2(tempPos.X + headPositions[0], tempPos.Y), Color.White);
                        Spritebatch.Draw(redHead, new Vector2(tempPos.X + headPositions[1], tempPos.Y), Color.White);
                    }
                    tempPos = new Vector2(tempPos.X - (screenBoundaries.Width * 0.5f), tempPos.Y + (screenBoundaries.Height * 0.5f));
                }
                else if (i == 2)
                {
                    if (headPositions.Count == 4)
                    {
                        Spritebatch.Draw(greenHead, new Vector2(tempPos.X + headPositions[3], tempPos.Y), Color.White);
                        Spritebatch.Draw(redHead, new Vector2(tempPos.X + headPositions[1], tempPos.Y), Color.White);
                        Spritebatch.Draw(blueHead, new Vector2(tempPos.X + headPositions[0], tempPos.Y), Color.White);
                        Spritebatch.Draw(yellowHead, new Vector2(tempPos.X + headPositions[2], tempPos.Y), Color.White);
                    }
                    else if (headPositions.Count == 3)
                    {
                        Spritebatch.Draw(redHead, new Vector2(tempPos.X + headPositions[1], tempPos.Y), Color.White);
                        Spritebatch.Draw(blueHead, new Vector2(tempPos.X + headPositions[0], tempPos.Y), Color.White);
                        Spritebatch.Draw(yellowHead, new Vector2(tempPos.X + headPositions[2], tempPos.Y), Color.White);
                    }
                    tempPos = new Vector2(tempPos.X + (screenBoundaries.Width * 0.5f), tempPos.Y);
                }
                else
                {
                    if (headPositions.Count == 4)
                    {
                        Spritebatch.Draw(yellowHead, new Vector2(tempPos.X + headPositions[2], tempPos.Y), Color.White);
                        Spritebatch.Draw(redHead, new Vector2(tempPos.X + headPositions[1], tempPos.Y), Color.White);
                        Spritebatch.Draw(blueHead, new Vector2(tempPos.X + headPositions[0], tempPos.Y), Color.White);
                        Spritebatch.Draw(greenHead, new Vector2(tempPos.X + headPositions[3], tempPos.Y), Color.White);
                    }
                }
            }

            if (playerAmount < 4)
            {
                Spritebatch.Draw(greenSquare, new Vector2(screenBoundaries.Width * 0.5f, screenBoundaries.Height * 0.5f), Color.White);
            }
            if (playerAmount < 3)
            {
                Spritebatch.Draw(yellowSquare, new Vector2(0f, screenBoundaries.Height * 0.5f), Color.White);
            }
            if (playerAmount < 2)
            {
                Spritebatch.Draw(redSquare, new Vector2(screenBoundaries.Width * 0.5f, 0f), Color.White);
            }

            tempPos = new Vector2(70f, 75f);
            Color color2 = new Color(4, 88, 120);
            Color focusColor = new Color(248, 148, 29);
            for (int i = 0; i < playerAmount; i++)
            {
                if (savingHighscore[i])
                {
                    switch (i)
                    {
                        case 0:
                            Spritebatch.Draw(saveBG, new Vector2(0f, 0f), Color.White);
                            
                            Spritebatch.DrawString(savingFont, "Congratulations!", new Vector2(tempPos.X + 330f - (savingFont.MeasureString("Congratulations!").X * 0.5f), tempPos.Y - 30f), color2);
                            Spritebatch.DrawString(savingFont, "Your time makes the highscore list!", new Vector2(tempPos.X, tempPos.Y + 55f), color2);
                            
                            tempText = times[i].GetValue(0).ToString() + ":";
                            if ((int)times[i].GetValue(1) < 10)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(1).ToString() + ":";
                            if ((int)times[i].GetValue(2) < 10)
                            {
                                tempText += "00";
                            }
                            else if ((int)times[i].GetValue(2) < 100)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(2).ToString();

                            tempPos.Y += 140f;
                            Spritebatch.DrawString(savingFont, "Your time: " + tempText, tempPos, color2);

                            tempPos.Y += 85f;
                            Spritebatch.DrawString(savingFont, "Your name: ", tempPos, color2);
                            if (firstFocus != 4)
                            {
                                if (firstFocus == 0)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[firstName[0]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[firstName[0]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), color2);
                                }
                                if (firstFocus == 1)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[firstName[1]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[firstName[0]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[firstName[1]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[firstName[0]]).X, tempPos.Y), color2);
                                }
                                if (firstFocus == 2)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[firstName[2]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[firstName[0]] + alpabet[firstName[1]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[firstName[2]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[firstName[0]] + alpabet[firstName[1]]).X, tempPos.Y), color2);
                                }
                                if (firstFocus == 3)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[firstName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[firstName[0]] + alpabet[firstName[1]] + alpabet[firstName[2]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[firstName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[firstName[0]] + alpabet[firstName[1]] + alpabet[firstName[2]]).X, tempPos.Y), color2);
                                }
                            }
                            else
                            {
                                Spritebatch.DrawString(savingFont, alpabet[firstName[0]] + alpabet[firstName[1]] + alpabet[firstName[2]] + alpabet[firstName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), color2);
                            }

                            tempPos.X += 400f;
                            Spritebatch.DrawString(savingFont, "Save? ", tempPos, color2);
                            if (firstFocus == 4)
                            {
                                Spritebatch.DrawString(savingFont, yesNo[yesNoIndex[i]], new Vector2(tempPos.X + savingFont.MeasureString("Save? ").X, tempPos.Y), focusColor);
                            }
                            else
                            {
                                Spritebatch.DrawString(savingFont, yesNo[yesNoIndex[i]], new Vector2(tempPos.X + savingFont.MeasureString("Save? ").X, tempPos.Y), color2);
                            }
                            break;
                        case 1 :
                            tempPos = new Vector2(70f + (screenBoundaries.Width * 0.5f), 75f);
                            Spritebatch.Draw(saveBG, new Vector2(screenBoundaries.Width * 0.5f, 0f), Color.White);

                            Spritebatch.DrawString(savingFont, "Congratulations!", new Vector2(tempPos.X + 330f - (savingFont.MeasureString("Congratulations!").X * 0.5f), tempPos.Y - 30f), color2);
                            Spritebatch.DrawString(savingFont, "Your time makes the highscore list!", new Vector2(tempPos.X, tempPos.Y + 55f), color2);

                            tempText = times[i].GetValue(0).ToString() + ":";
                            if ((int)times[i].GetValue(1) < 10)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(1).ToString() + ":";
                            if ((int)times[i].GetValue(2) < 10)
                            {
                                tempText += "00";
                            }
                            else if ((int)times[i].GetValue(2) < 100)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(2).ToString();

                            tempPos.Y += 140f;
                            Spritebatch.DrawString(savingFont, "Your time: " + tempText, tempPos, color2);

                            tempPos.Y += 85f;
                            Spritebatch.DrawString(savingFont, "Your name: ", tempPos, color2);
                            if (secondFocus != 4)
                            {
                                if (secondFocus == 0)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[secondName[0]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[secondName[0]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), color2);
                                }
                                if (secondFocus == 1)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[secondName[1]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[secondName[0]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[secondName[1]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[secondName[0]]).X, tempPos.Y), color2);
                                }
                                if (secondFocus == 2)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[secondName[2]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[secondName[0]] + alpabet[secondName[1]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[secondName[2]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[secondName[0]] + alpabet[secondName[1]]).X, tempPos.Y), color2);
                                }
                                if (secondFocus == 3)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[secondName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[secondName[0]] + alpabet[secondName[1]] + alpabet[secondName[2]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[secondName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[secondName[0]] + alpabet[secondName[1]] + alpabet[secondName[2]]).X, tempPos.Y), color2);
                                }
                            }
                            else
                            {
                                Spritebatch.DrawString(savingFont, alpabet[secondName[0]] + alpabet[secondName[1]] + alpabet[secondName[2]] + alpabet[secondName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), color2);
                            }

                            tempPos.X += 400f;
                            Spritebatch.DrawString(savingFont, "Save? ", tempPos, color2);
                            if (secondFocus == 4)
                            {
                                Spritebatch.DrawString(savingFont, yesNo[yesNoIndex[i]], new Vector2(tempPos.X + savingFont.MeasureString("Save? ").X, tempPos.Y), focusColor);
                            }
                            else
                            {
                                Spritebatch.DrawString(savingFont, yesNo[yesNoIndex[i]], new Vector2(tempPos.X + savingFont.MeasureString("Save? ").X, tempPos.Y), color2);
                            }
                            break;
                        case 2 :
                            tempPos = new Vector2(70f, 75f + (screenBoundaries.Height * 0.5f));
                            Spritebatch.Draw(saveBG, new Vector2(0f, screenBoundaries.Height * 0.5f), Color.White);

                            Spritebatch.DrawString(savingFont, "Congratulations!", new Vector2(tempPos.X + 330f - (savingFont.MeasureString("Congratulations!").X * 0.5f), tempPos.Y - 30f), color2);
                            Spritebatch.DrawString(savingFont, "Your time makes the highscore list!", new Vector2(tempPos.X, tempPos.Y + 55f), color2);

                            tempText = times[i].GetValue(0).ToString() + ":";
                            if ((int)times[i].GetValue(1) < 10)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(1).ToString() + ":";
                            if ((int)times[i].GetValue(2) < 10)
                            {
                                tempText += "00";
                            }
                            else if ((int)times[i].GetValue(2) < 100)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(2).ToString();

                            tempPos.Y += 140f;
                            Spritebatch.DrawString(savingFont, "Your time: " + tempText, tempPos, color2);

                            tempPos.Y += 85f;
                            Spritebatch.DrawString(savingFont, "Your name: ", tempPos, color2);
                            if (thirdFocus != 4)
                            {
                                if (thirdFocus == 0)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[thirdName[0]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[thirdName[0]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), color2);
                                }
                                if (thirdFocus == 1)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[thirdName[1]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[thirdName[0]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[thirdName[1]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[thirdName[0]]).X, tempPos.Y), color2);
                                }
                                if (thirdFocus == 2)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[thirdName[2]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[thirdName[0]] + alpabet[thirdName[1]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[thirdName[2]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[thirdName[0]] + alpabet[thirdName[1]]).X, tempPos.Y), color2);
                                }
                                if (thirdFocus == 3)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[thirdName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[thirdName[0]] + alpabet[thirdName[1]] + alpabet[thirdName[2]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[thirdName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[thirdName[0]] + alpabet[thirdName[1]] + alpabet[thirdName[2]]).X, tempPos.Y), color2);
                                }
                            }
                            else
                            {
                                Spritebatch.DrawString(savingFont, "Your name: " + alpabet[thirdName[0]] + alpabet[thirdName[1]] + alpabet[thirdName[2]] + alpabet[thirdName[3]], tempPos, color2);
                            }

                            tempPos.X += 400f;
                            Spritebatch.DrawString(savingFont, "Save? ", tempPos, color2);
                            if (thirdFocus == 4)
                            {
                                Spritebatch.DrawString(savingFont, yesNo[yesNoIndex[i]], new Vector2(tempPos.X + savingFont.MeasureString("Save? ").X, tempPos.Y), focusColor);
                            }
                            else
                            {
                                Spritebatch.DrawString(savingFont, yesNo[yesNoIndex[i]], new Vector2(tempPos.X + savingFont.MeasureString("Save? ").X, tempPos.Y), color2);
                            }
                            break;
                        case 3:
                            tempPos = new Vector2(70f + (screenBoundaries.Width * 0.5f), 75f + (screenBoundaries.Height * 0.5f));
                            Spritebatch.Draw(saveBG, new Vector2(screenBoundaries.Width * 0.5f, screenBoundaries.Height * 0.5f), Color.White);

                            Spritebatch.DrawString(savingFont, "Congratulations!", new Vector2(tempPos.X + 330f - (savingFont.MeasureString("Congratulations!").X * 0.5f), tempPos.Y - 30f), color2);
                            Spritebatch.DrawString(savingFont, "Your time makes the highscore list!", new Vector2(tempPos.X, tempPos.Y + 55f), color2);

                            tempText = times[i].GetValue(0).ToString() + ":";
                            if ((int)times[i].GetValue(1) < 10)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(1).ToString() + ":";
                            if ((int)times[i].GetValue(2) < 10)
                            {
                                tempText += "00";
                            }
                            else if ((int)times[i].GetValue(2) < 100)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(2).ToString();

                            tempPos.Y += 140f;
                            Spritebatch.DrawString(savingFont, "Your time: " + tempText, tempPos, color2);

                            tempPos.Y += 85f;
                            Spritebatch.DrawString(savingFont, "Your name: ", tempPos, color2);
                            if (fourthFocus != 4)
                            {
                                if (fourthFocus == 0)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[fourthName[0]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[fourthName[0]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), color2);
                                }
                                if (fourthFocus == 1)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[fourthName[1]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[fourthName[0]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[fourthName[1]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[fourthName[0]]).X, tempPos.Y), color2);
                                }
                                if (fourthFocus == 2)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[fourthName[2]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[fourthName[0]] + alpabet[fourthName[1]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[fourthName[2]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[fourthName[0]] + alpabet[fourthName[1]]).X, tempPos.Y), color2);
                                }
                                if (fourthFocus == 3)
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[fourthName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[fourthName[0]] + alpabet[fourthName[1]] + alpabet[fourthName[2]]).X, tempPos.Y), focusColor);
                                }
                                else
                                {
                                    Spritebatch.DrawString(savingFont, alpabet[fourthName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: " + alpabet[fourthName[0]] + alpabet[fourthName[1]] + alpabet[fourthName[2]]).X, tempPos.Y), color2);
                                }
                            }
                            else
                            {
                                Spritebatch.DrawString(savingFont, "Your name: " + alpabet[fourthName[0]] + alpabet[fourthName[1]] + alpabet[fourthName[2]] + alpabet[fourthName[3]], tempPos, color2);
                            }

                            tempPos.X += 400f;
                            Spritebatch.DrawString(savingFont, "Save? ", tempPos, color2);
                            if (fourthFocus == 4)
                            {
                                Spritebatch.DrawString(savingFont, yesNo[yesNoIndex[i]], new Vector2(tempPos.X + savingFont.MeasureString("Save? ").X, tempPos.Y), focusColor);
                            }
                            else
                            {
                                Spritebatch.DrawString(savingFont, yesNo[yesNoIndex[i]], new Vector2(tempPos.X + savingFont.MeasureString("Save? ").X, tempPos.Y), color2);
                            }
                            break;
                    }
                }
                else if (!savingHighscore[i] && playerManager.GetPlayer(i).CurrentState == (int)Enums.State.FINISHED)
                {
                    switch (i)
                    {
                        case 0:
                            Spritebatch.Draw(saveBG, new Vector2(0f, 0f), Color.White);
                            if (!noHighscore[i])
                            {
                                Spritebatch.DrawString(savingFont, "Congratulations!", new Vector2(tempPos.X + 330f - (savingFont.MeasureString("Congratulations!").X * 0.5f), tempPos.Y - 30f), color2);
                                Spritebatch.DrawString(savingFont, "Your time makes the highscore list!", new Vector2(tempPos.X, tempPos.Y + 55f), color2);
                            }

                            tempText = times[i].GetValue(0).ToString() + ":";
                            if ((int)times[i].GetValue(1) < 10)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(1).ToString() + ":";
                            if ((int)times[i].GetValue(2) < 10)
                            {
                                tempText += "00";
                            }
                            else if ((int)times[i].GetValue(2) < 100)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(2).ToString();

                            tempPos.Y += 140f;
                            Spritebatch.DrawString(savingFont, "Your time: " + tempText, tempPos, color2);

                            if (!noHighscore[i])
                            {
                                tempPos.Y += 85f;
                                Spritebatch.DrawString(savingFont, "Your name: ", tempPos, color2);
                                Spritebatch.DrawString(savingFont, alpabet[firstName[0]] + alpabet[firstName[1]] + alpabet[firstName[2]] + alpabet[firstName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), color2);

                                tempPos.X += 400f;
                                Spritebatch.DrawString(savingFont, "Saved", tempPos, color2);
                            }
                            break;
                        case 1:
                            tempPos = new Vector2(70f + (screenBoundaries.Width * 0.5f), 75f);
                            Spritebatch.Draw(saveBG, new Vector2(screenBoundaries.Width * 0.5f, 0f), Color.White);
                            if (!noHighscore[i])
                            {
                                Spritebatch.DrawString(savingFont, "Congratulations!", new Vector2(tempPos.X + 330f - (savingFont.MeasureString("Congratulations!").X * 0.5f), tempPos.Y - 30f), color2);
                                Spritebatch.DrawString(savingFont, "Your time makes the highscore list!", new Vector2(tempPos.X, tempPos.Y + 55f), color2);
                            }

                            tempText = times[i].GetValue(0).ToString() + ":";
                            if ((int)times[i].GetValue(1) < 10)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(1).ToString() + ":";
                            if ((int)times[i].GetValue(2) < 10)
                            {
                                tempText += "00";
                            }
                            else if ((int)times[i].GetValue(2) < 100)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(2).ToString();

                            tempPos.Y += 140f;
                            Spritebatch.DrawString(savingFont, "Your time: " + tempText, tempPos, color2);

                            if (!noHighscore[i])
                            {
                                tempPos.Y += 85f;
                                Spritebatch.DrawString(savingFont, "Your name: ", tempPos, color2);
                                Spritebatch.DrawString(savingFont, alpabet[secondName[0]] + alpabet[secondName[1]] + alpabet[secondName[2]] + alpabet[secondName[3]], new Vector2(tempPos.X + savingFont.MeasureString("Your name: ").X, tempPos.Y), color2);

                                tempPos.X += 400f;
                                Spritebatch.DrawString(savingFont, "Saved", tempPos, color2);
                            }
                            break;
                        case 2:
                            tempPos = new Vector2(70f, 75f + (screenBoundaries.Height * 0.5f));
                            Spritebatch.Draw(saveBG, new Vector2(0f, screenBoundaries.Height * 0.5f), Color.White);

                            if (!noHighscore[i])
                            {
                                Spritebatch.DrawString(savingFont, "Congratulations!", new Vector2(tempPos.X + 330f - (savingFont.MeasureString("Congratulations!").X * 0.5f), tempPos.Y - 30f), color2);
                                Spritebatch.DrawString(savingFont, "Your time makes the highscore list!", new Vector2(tempPos.X, tempPos.Y + 55f), color2);
                            }

                            tempText = times[i].GetValue(0).ToString() + ":";
                            if ((int)times[i].GetValue(1) < 10)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(1).ToString() + ":";
                            if ((int)times[i].GetValue(2) < 10)
                            {
                                tempText += "00";
                            }
                            else if ((int)times[i].GetValue(2) < 100)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(2).ToString();

                            tempPos.Y += 140f;
                            Spritebatch.DrawString(savingFont, "Your time: " + tempText, tempPos, color2);

                            if (!noHighscore[i])
                            {
                                tempPos.Y += 85f;
                                Spritebatch.DrawString(savingFont, "Your name: ", tempPos, color2);
                                Spritebatch.DrawString(savingFont, "Your name: " + alpabet[thirdName[0]] + alpabet[thirdName[1]] + alpabet[thirdName[2]] + alpabet[thirdName[3]], tempPos, color2);

                                tempPos.X += 400f;
                                Spritebatch.DrawString(savingFont, "Saved", tempPos, color2);
                            }
                            break;
                        case 3:
                            tempPos = new Vector2(70f + (screenBoundaries.Width * 0.5f), 75f + (screenBoundaries.Height * 0.5f));
                            Spritebatch.Draw(saveBG, new Vector2(screenBoundaries.Width * 0.5f, screenBoundaries.Height * 0.5f), Color.White);

                            if (!noHighscore[i])
                            {
                                Spritebatch.DrawString(savingFont, "Congratulations!", new Vector2(tempPos.X + 330f - (savingFont.MeasureString("Congratulations!").X * 0.5f), tempPos.Y - 30f), color2);
                                Spritebatch.DrawString(savingFont, "Your time makes the highscore list!", new Vector2(tempPos.X, tempPos.Y + 55f), color2);
                            }

                            tempText = times[i].GetValue(0).ToString() + ":";
                            if ((int)times[i].GetValue(1) < 10)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(1).ToString() + ":";
                            if ((int)times[i].GetValue(2) < 10)
                            {
                                tempText += "00";
                            }
                            else if ((int)times[i].GetValue(2) < 100)
                            {
                                tempText += "0";
                            }
                            tempText += times[i].GetValue(2).ToString();

                            tempPos.Y += 140f;
                            Spritebatch.DrawString(savingFont, "Your time: " + tempText, tempPos, color2);

                            if (!noHighscore[i])
                            {
                                tempPos.Y += 85f;
                                Spritebatch.DrawString(savingFont, "Your name: ", tempPos, color2);
                                Spritebatch.DrawString(savingFont, "Your name: " + alpabet[fourthName[0]] + alpabet[fourthName[1]] + alpabet[fourthName[2]] + alpabet[fourthName[3]], tempPos, color2);

                                tempPos.X += 400f;
                                Spritebatch.DrawString(savingFont, "Saved", tempPos, color2);
                            }
                            break;
                    }
                }
            }

            Spritebatch.End();

            base.Draw(gameTime);
        }

        public override string GetNextScreen()
        {
            return nextScreen;
        }

        private List<short> CalculatePlayerPlaces()
        {
            /*bool[] activePlayers = score.ActivePlayers;
            List<short> currentPlayerPlaces = score.PlayerPlaces;

            short place = 1;
            for (int i = 0; i < playerAmount; i++)
            {
                if (!activePlayers[i])
                {
                    place++;
                }
            }

            List<float> playerXs = new List<float>(playerAmount);
            for (int i = 0; i < playerAmount; i++)
            {
                playerXs.Add(playerManager.GetPlayerPosition(i).X);
            }

            int maxPlacement = playerAmount + 1;
            bool sameX = false;

            do
            {
                float tempX = 0;
                int i = 0;
                for (; i < playerAmount; i++)
                {
                    if (activePlayers[i] && tempX < playerXs[i])
                    {
                        tempX = playerXs[i];
                    }
                    else if (activePlayers[i] && tempX == playerXs[i])
                    {
                        sameX = true;
                    }
                }
                if (tempX != 0)
                {
                    currentPlayerPlaces[playerXs.IndexOf(tempX)] = place;
                    playerXs[playerXs.IndexOf(tempX)] = 0f;
                }
                if (!sameX)
                {
                    place++;
                }
                else
                {
                    maxPlacement--;
                }
                sameX = false;
            } while (place < maxPlacement);

            return currentPlayerPlaces;*/

            List<short> playerPlaces = new List<short>(playerAmount);
            for (int i = 0; i < playerAmount; i++)
            {
                playerPlaces.Add(4);
            }

            List<float> playerXs = new List<float>(playerAmount);
            List<float> forSortingPlayerXs = new List<float>(playerAmount);
            List<float> sortedPlayerXs = new List<float>(playerAmount);
            for (int i = 0; i < playerAmount; i++)
            {
                playerXs.Add(playerManager.GetPlayerPosition(i).X);
                forSortingPlayerXs.Add(playerManager.GetPlayerPosition(i).X);
            }

            do
            {
                float tempX = forSortingPlayerXs[0];
                for (int i = 1; i < forSortingPlayerXs.Count; i++)
                {
                    if (tempX < forSortingPlayerXs[i])
                    {
                        tempX = forSortingPlayerXs[i];
                    }
                }
                sortedPlayerXs.Add(tempX);
                forSortingPlayerXs.Remove(tempX);
            } while (sortedPlayerXs.Count < playerAmount);

            for (int i = 0; i < playerAmount; i++)
            {
                if (playerXs[i] == sortedPlayerXs[0])
                {
                    playerPlaces[i] = 1;
                }
                else if (playerXs[i] == sortedPlayerXs[1])
                {
                    playerPlaces[i] = 2;
                }
                else if (playerXs[i] == sortedPlayerXs[2])
                {
                    playerPlaces[i] = 3;
                }
                else if (playerXs[i] == sortedPlayerXs[3])
                {
                    playerPlaces[i] = 4;
                }                
            }

            return playerPlaces;
        }

        private void DrawCity(float x1, float x2)
        {
            if (x1 >= 0 && x1 <= cityTexture.Width || x2 >= 0 && x2 <= cityTexture.Width)
            {
                //Spritebatch.Draw(cityTexture, new Vector2(0, 1472f - cityTexture.Height), Color.White);
                Spritebatch.Draw(ci, new Vector2(0, 1472f - ci.Height), Color.White);
                Spritebatch.Draw(ty, new Vector2(0 + ci.Width, 1472f - ty.Height), Color.White);
            }
            if (x1 >= cityTexture.Width && x1 <= (cityTexture.Width * 2) || x2 >= cityTexture.Width && x2 <= (cityTexture.Width * 2))
            {
                //Spritebatch.Draw(cityTexture, new Vector2(cityTexture.Width, 1472f - cityTexture.Height), Color.White);
                Spritebatch.Draw(ci, new Vector2(ci.Width + ty.Width, 1472f - ci.Height), Color.White);
                Spritebatch.Draw(ty, new Vector2((ci.Width + ty.Width) + ci.Width, 1472f - ty.Height), Color.White);
            }
            if (x1 >= (cityTexture.Width * 2) && x1 <= (cityTexture.Width * 3) || x2 >= (cityTexture.Width * 2) && x2 <= (cityTexture.Width * 3))
            {
                //Spritebatch.Draw(cityTexture, new Vector2(cityTexture.Width * 2, 1472f - cityTexture.Height), Color.White);
                Spritebatch.Draw(ci, new Vector2((ci.Width + ty.Width) * 2, 1472f - ci.Height), Color.White);
                Spritebatch.Draw(ty, new Vector2(((ci.Width + ty.Width) * 2) + ci.Width, 1472f - ty.Height), Color.White);
            }
            if (x1 >= (cityTexture.Width * 3) && x1 <= (cityTexture.Width * 4) || x2 >= (cityTexture.Width * 3) && x2 <= (cityTexture.Width * 4))
            {
                //Spritebatch.Draw(cityTexture, new Vector2(cityTexture.Width * 3, 1472f - cityTexture.Height), Color.White);
                Spritebatch.Draw(ci, new Vector2((ci.Width + ty.Width) * 3, 1472f - ci.Height), Color.White);
                Spritebatch.Draw(ty, new Vector2(((ci.Width + ty.Width) * 3) + ci.Width, 1472f - ty.Height), Color.White);
            }
            if (x1 >= (cityTexture.Width * 4) && x1 <= (cityTexture.Width * 5) || x2 >= (cityTexture.Width * 4) && x2 <= (cityTexture.Width * 5))
            {
                //Spritebatch.Draw(cityTexture, new Vector2(cityTexture.Width * 4, 1472f - cityTexture.Height), Color.White);
                Spritebatch.Draw(ci, new Vector2((ci.Width + ty.Width) * 4, 1472f - ci.Height), Color.White);
                Spritebatch.Draw(ty, new Vector2(((ci.Width + ty.Width) * 4) + ci.Width, 1472f - ty.Height), Color.White);
            }
            if (x1 >= (cityTexture.Width * 5) && x1 <= (cityTexture.Width * 6) || x2 >= (cityTexture.Width * 5) && x2 <= (cityTexture.Width * 6))
            {
                //Spritebatch.Draw(cityTexture, new Vector2(cityTexture.Width * 5, 1472f - cityTexture.Height), Color.White);
                Spritebatch.Draw(ci, new Vector2((ci.Width + ty.Width) * 5, 1472f - ci.Height), Color.White);
                Spritebatch.Draw(ty, new Vector2(((ci.Width + ty.Width) * 5) + ci.Width, 1472f - ty.Height), Color.White);
            }
            if (x1 >= (cityTexture.Width * 6) && x1 <= (cityTexture.Width * 7) || x2 >= (cityTexture.Width * 6) && x2 <= (cityTexture.Width * 7))
            {
                //Spritebatch.Draw(cityTexture, new Vector2(cityTexture.Width * 6, 1472f - cityTexture.Height), Color.White);
                Spritebatch.Draw(ci, new Vector2((ci.Width + ty.Width) * 6, 1472f - ci.Height), Color.White);
                Spritebatch.Draw(ty, new Vector2(((ci.Width + ty.Width) * 6) + ci.Width, 1472f - ty.Height), Color.White);
            }
            if (x1 >= (cityTexture.Width * 7) && x1 <= (cityTexture.Width * 8) || x2 >= (cityTexture.Width * 7) && x2 <= (cityTexture.Width * 8))
            {
                //Spritebatch.Draw(cityTexture, new Vector2(cityTexture.Width * 7, 1472f - cityTexture.Height), Color.White);
                Spritebatch.Draw(ci, new Vector2((ci.Width + ty.Width) * 7, 1472f - ci.Height), Color.White);
                Spritebatch.Draw(ty, new Vector2(((ci.Width + ty.Width) * 7) + ci.Width, 1472f - ty.Height), Color.White);
            }
            if (x1 >= (cityTexture.Width * 8) && x1 <= (cityTexture.Width * 9) || x2 >= (cityTexture.Width * 8) && x2 <= (cityTexture.Width * 9))
            {
                //Spritebatch.Draw(cityTexture, new Vector2(cityTexture.Width * 8, 1472f - cityTexture.Height), Color.White);
                Spritebatch.Draw(ci, new Vector2((ci.Width + ty.Width) * 8, 1472f - ci.Height), Color.White);
                Spritebatch.Draw(ty, new Vector2(((ci.Width + ty.Width) * 8) + ci.Width, 1472f - ty.Height), Color.White);
            }
            if (x1 >= (cityTexture.Width * 9) && x1 <= (cityTexture.Width * 10) || x2 >= (cityTexture.Width * 9) && x2 <= (cityTexture.Width * 10))
            {
                //Spritebatch.Draw(cityTexture, new Vector2(cityTexture.Width * 9, 1472f - cityTexture.Height), Color.White);
                Spritebatch.Draw(ci, new Vector2((ci.Width + ty.Width) * 9, 1472f - ci.Height), Color.White);
                Spritebatch.Draw(ty, new Vector2(((ci.Width + ty.Width) * 9) + ci.Width, 1472f - ty.Height), Color.White);
            }
            if (x1 >= (cityTexture.Width * 10) && x1 <= (cityTexture.Width * 11) || x2 >= (cityTexture.Width * 10) && x2 <= (cityTexture.Width * 11))
            {
                Spritebatch.Draw(ci, new Vector2((ci.Width + ty.Width) * 10, 1472f - ci.Height), Color.White);
            }
        }

        private List<float> MapHeadPositions()
        {
            List<float> positions = new List<float>();

            List<Vector2> tempList = playerManager.GetPlayerPositions();
            List<float> tempFloat = new List<float>();
            float levelLength = levelEnd - 170f;

            for (int i = 0; i < tempList.Count; i++)
            {
                tempFloat.Add(tempList[i].X - 170f);
            }

            for (int j = 0; j < tempFloat.Count; j++)
            {
                if (tempFloat[j] <= 0f)
                {
                    positions.Add(0f);
                }
                else if (tempFloat[j] >= levelLength)
                {
                    positions.Add(449f);
                }
                else
                {
                    float temp = tempFloat[j] / levelLength;
                    positions.Add(449f * temp);
                }
            }

            return positions;
        }

        void DrawFinish(float x1, float x2)
        {
            if (x1 >= levelEnd - 48f || x2 >= levelEnd - 48f)
            {
                Spritebatch.Draw(finish, new Vector2(levelEnd - 126f, 1440f - finish.Height), Color.White);
            }
        }
    }
}
